<?php
$path=$_SERVER['PHP_SELF'];
$url=pathinfo($path,PATHINFO_BASENAME);
$urlname=basename($url,".php");
$userId = $_SESSION["userId"];
$menu = $urlname;
switch ($urlname){
  	case friendlist:$subfriendlist="class='subchangenvbg'";break;
  	case friendmanage:$friendmanage="class='subchangenvbg'";break;
  	case financemanage:$financemanage="class='subchangenvbg'";break;
  	case blog:$blog="class='subchangenvbg'";break;
  	case bloglist:$bloglistNav="class='subchangenvbg'";$menu="blog";break;
  	case pictures:$pictures="class='subchangenvbg'";break;
  	case event:$event="class='subchangenvbg'";break;
  	case preinfo:$preinfo="class='subchangenvbg'";break;
  	
}
?>
<div id="subnavigation">
  	<ul id="subnaviul">
	  	<li <?php echo $blog;echo $bloglistNav ?>><a class="astyle" href="bloglist.php?userId=<?php echo $userId;?>"><span class="acolor">博客</span></a></li>
	  	<li <?php echo $subfriendlist;echo $friendmanage; ?>><a class="astyle" href="friendlist.php"><span class="acolor">通讯录</span></a></li>
	  	<li <?php echo $financemanage ?>><a class="astyle" href="financemanage.php"><span class="acolor">财务</span></a></li>
	  	<li <?php echo $pictures ?>><a class="astyle" href="pictures.php?userId=<?php echo $userId;?>"><span class="acolor">相册</span></a></li>
	  	<li <?php echo $event ?>><a class="astyle" href="event.php"><span class="acolor">事件</span></a></li>
	  	<li <?php echo $preinfo ?>><a class="astyle" href="preinfo.php"><span class="acolor">个人中心</span></a></li>
	  	<li><a class="astyle" onclick="loginout()"><span class="acolor">退出</span></a></li>
	  	<li class="searchMenu"><input id="searchTopInput" value="" name="search" /><input type="button" class="topSearch" value="Search" /></li>
  	</ul>
</div>
<script type="text/javascript">
function loginout(){
	var con=confirm('确定退出？');
	if (con){	
	  window.location.href='logout.php'; 
	}
	else{
		return false;
	}
}
$(document).ready(function(){
	window.searchHandle=1;
	$(".topSearch").click(blogSearch);
	$("#searchTopInput").keydown(function(){
		var e = window.event || arguments[0];
		var keycodeTemp = e.keyCode;
		var keyChar = (String.fromCharCode(keycodeTemp)).substr(1);
		if(keycodeTemp==13)
			blogSearch();
	});
	$(document).keyup(function(){
		var e = window.event || arguments[0];
		var temp = String.fromCharCode(e.keyCode)
		//ctr+. go to search button
		if(e.keyCode==190){
			$("#searchTopInput").focus();
		}
	})
})
function blogSearch(){
	var data = {};
	data.menu = "<?php echo $menu?>";
	data.key = $("#searchTopInput").val();
	data.url = "searchAjax.php";
	if(!data.key){
		HHL.newAlertMes("请输入关键词！","","1500");
		$("#topSearchResults").remove();
		return false;
	}
	$.ajax({
		type:"POST",
		data:data,
		url:data.url,
		success:function(responseData){
			$("div[id^='kindMessage0']").remove();
			$("#topSearchResults").remove();
			if(!responseData){
				responseData="没有搜索到。。。";
			}
			var searchView = "<div id='topSearchResults'><img src='style/close.jpg' class='searchClose' onclick=\"closeSearch()\" onmouseover=\"searchOver()\" onmouseout=\"searchOut()\">"+responseData+"</div>";
			$("body").append(searchView);
			$("#topSearchResults .blogiterm").dblclick(function(){
				getDetailBlog(this);
			})
		},
		beforeSend:function(){
			HHL.newMes("<img src='style/load.gif' />Start To Search ...","z-index:7","1000");
		}
	});

}
function getDetailBlog(ob){
	/*if(!window.searchHandle==1){
		return false;
	}*/
	window.blogOb = $(ob);
	if(blogOb.find(".blogDetailDynamic").html()&&blogOb.find(".blogtext").css('display')=='none'){
		blogOb.find(".blogDetailDynamic").css({"display":"none"});
		blogOb.find(".blogtext").css({"display":"block"});
		blogOb.focus();
		window.searchHandle=1;
		return true;
	}else if(blogOb.find(".blogDetailDynamic").html()&&(blogOb.find(".blogtext").css('display')=='block')){
		blogOb.find(".blogDetailDynamic").css({"display":"block"});
		blogOb.find(".blogtext").css({"display":"none"});
		blogOb.find(".blogDetailDynamic").find(".blogtext").css({"display":"block"});
//		var test =blogOb.find(".blogDetailDynamic").find(".blogtext").html();
//		alert(test);	
		blogOb.focus();
		window.searchHandle=1;
		return true;
	}
	var data={};
	var objects= $(ob).find(".blogtext");
	var blogIdFull = $(ob).attr('id');
	blogId = blogIdFull.substr(6);
	window.blogIdTemp =blogId;
	data.blogId=blogId;
	data.menu="blogDetail";
	data.url="searchAjax.php";
	$.ajax({
		type:"POST",
		data:data,
		url:data.url,
		beforeSend:function(){
			window.searchHandle=0;
			HHL.newMes("<img src='config/images/loading.gif' />Loading...");
		},
		success:function(resData){
			jQuery("div[id^='kindMessage00']").remove();
			blogOb.find(".blogtext").css({"display":"none"});
			var dynamic=blogOb.find(".blogDetailDynamic");
			if(dynamic.html()){
				var newHtml =resData;
				dynamic.append(newHtml);
			}else{
				var newHtml = "<div class='blogDetailDynamic'>"+resData+"</div>";
				var appendit = blogOb.append(newHtml);
			}
			
			window.searchHandle=1;
			//alert(appendit)
		},
		error:function(){
			window.searchHandle=1;
		}
	})
}
function closeSearch(){
	$("#topSearchResults").remove();
}
function searchOver(){
	$(".searchClose").css({"opacity":"1","filter":"Alpha(Opacity='100',FinishOpacity='50',Style='2')"})
}
function searchOut(){
	$(".searchClose").css({"opacity":"0.5","filter":"Alpha(Opacity='50',FinishOpacity='50',Style='2')"})
}
</script> 